package com.atguigu.spzx.service.cart.controller;

import com.atguigu.spzx.service.cart.service.CartService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.entity.h5.CartInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * title:
 * author: zgl
 * date: 2024/1/17
 * description：
 */
@RestController
@RequestMapping("/api/order/cart/auth")
@Tag(name = "购物车模块")
public class CartController {
    @Resource
    private CartService cartService;

    @Operation(summary = "添加购物车接口")
    @GetMapping("/addToCart/{skuId}/{skuNum}")
    public Result addToCart(@PathVariable Long skuId, @PathVariable Integer skuNum) {
        cartService.addToCart(skuId, skuNum);
        return Result.ok();
    }

    @Operation(summary = "查看购物车接口")
    @GetMapping("/cartList")
    public Result cartList() {
        List<CartInfo> cartInfoList = cartService.cartList();
        return Result.ok(cartInfoList);
    }

    @Operation(summary = "删除指定购物车列表接口")
    @DeleteMapping("/deleteCart/{skuId}")
    public Result deleteCart(@PathVariable Long skuId) {
        cartService.deleteCart(skuId);
        return Result.ok();
    }

    @Operation(summary = "取消或选中指定商品")
    @GetMapping("/checkCart/{skuId}/{isChecked}")
    public Result checkCart(@PathVariable Long skuId, @PathVariable Integer isChecked) {
        cartService.checkCart(skuId, isChecked);
        return Result.ok();
    }

    @Operation(summary = "全选或取消全选购物车sp接口")
    @GetMapping("/allCheckCart/{isChecked}")
    public Result allCheckCart(@PathVariable Integer isChecked) {
        cartService.allCheckCart(isChecked);
        return Result.ok();
    }

    @Operation(summary = "清空购物车所有商品接口")
    @GetMapping("/clearCart")
    public Result clearCart() {
        cartService.clearCart();
        return Result.ok();
    }

    @Operation(summary = "获取选中的购物车商品接口")
    @GetMapping("/getAllCkecked")
    public Result getCheckedList() {
        List<CartInfo> checkedList = cartService.getCheckedList();
        return Result.ok(checkedList);
    }

    @Operation(summary = "删除选中的购物车")
    @GetMapping("/deleteChecked")
    public Result deleteChecked() {
        cartService.deleteChecked();
        return Result.ok();
    }
}
